﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CreateWPOnRobotTCPF.CApCreateWpOnTCPFEnable
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.CreateWeldPoint;
using System;
using System.Collections.ObjectModel;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.PrivateImplementationDetails;


namespace DnProcessSimulateCommands.CreateWPOnRobotTCPF;

internal class CApCreateWpOnTCPFEnable : ITxCommandEnabler
{
  private bool CheckEnable()
  {
    bool flag = false;
    if (TxApplication.ActiveDocument.PlatformGlobalServicesProvider.IsDataLoaded())
    {
      if (TxTcUtilities.IsTcAnyPlatform)
      {
        if (TxApplication.ActiveSelection.TotalCount == 0 || this.IsSelectionValid())
          flag = true;
      }
      else
        flag = this.IsSelectionValid();
    }
    return flag;
  }

  private bool IsSelectionValid()
  {
    bool flag = true;
    TxTypeFilter txTypeFilter1 = new TxTypeFilter(new Type[4]
    {
      typeof (TxRobot),
      typeof (TxGun),
      typeof (TxServoGun),
      typeof (TxPneumaticServoGun)
    });
    TxTypeFilter txTypeFilter2 = new TxTypeFilter(txTypeFilter1);
    TxObjectList filteredItems1 = TxApplication.ActiveSelection.GetFilteredItems((ITxTypeFilter) txTypeFilter1);
    if (filteredItems1 != null)
      flag = !TxTcUtilities.IsTcAnyPlatform ? ((Collection<ITxObject>) filteredItems1).Count == 1 : ((Collection<ITxObject>) filteredItems1).Count <= 1;
    if (TxTcUtilities.IsTcAnyPlatform)
    {
      CApCreateWpTCLogic capCreateWpTcLogic = new CApCreateWpTCLogic();
      if (flag && !capCreateWpTcLogic.IsWeldPointPrivate)
      {
        TxTypeFilter txTypeFilter3 = new TxTypeFilter();
        foreach (Type allowedType in capCreateWpTcLogic.WeldContainerValidator.AllowedTypes)
        {
          txTypeFilter3.AddIncludedType(allowedType);
          txTypeFilter2.AddIncludedType(allowedType);
        }
        TxObjectList filteredItems2 = TxApplication.ActiveSelection.GetFilteredItems((ITxTypeFilter) txTypeFilter3);
        if (filteredItems2 != null)
          flag = ((Collection<ITxObject>) filteredItems2).Count <= 1;
      }
      if (flag)
      {
        TxTypeFilter txTypeFilter4 = new TxTypeFilter();
        foreach (Type allowedType in capCreateWpTcLogic.WeldOperationValidator.AllowedTypes)
        {
          txTypeFilter4.AddIncludedType(allowedType);
          txTypeFilter2.AddIncludedType(allowedType);
        }
        TxObjectList filteredItems3 = TxApplication.ActiveSelection.GetFilteredItems((ITxTypeFilter) txTypeFilter4);
        if (filteredItems3 != null)
          flag = ((Collection<ITxObject>) filteredItems3).Count == 0 || ((Collection<ITxObject>) filteredItems3).Count == 1 && ((Collection<ITxObject>) filteredItems3)[0].CanBeModified;
      }
    }
    return flag && ((Collection<ITxObject>) TxApplication.ActiveSelection.GetFilteredItems((ITxTypeFilter) txTypeFilter2)).Count == TxApplication.ActiveSelection.Count;
  }

  public bool Enable => this.CheckEnable();
}
